import Vue from 'vue'
import Vuex from 'vuex'
import goods from './goods'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 登录框
    isOpenLogin: false,
    // 购物车和登录按钮
    isgouwucheAndLogin: false,

    toast: {
      show: false,
      content: "你好",
      icon: "icon-toast_chenggong"
    },
    // 用户为登录的时候
    UresInfo: {
      headImg: require("@/assets/images/userImg.png"),
      nickName: "游客",
      coin: "--",
    },
    // 购物车数量
    cartTotal: "0",
  },
  getters: {
  },
  mutations: {
    changeIsOpenLogin(state, payload) {
      state.isOpenLogin = payload
    },
    changeisgouwucheAndLogin(state, payload) {
      state.isgouwucheAndLogin = payload
    },
    // 打开提示组件Toast
    openToast(state, payload) {
      state.toast.show = true,
        state.toast.content = payload.content
      switch (payload.icon) {
        case 'info':
          state.toast.icon = 'icon-toast-jinggao'
          break;
        case "success":
          state.toast.icon = "icon-toast_chenggong";
          break;
        case "danger":
          state.toast.icon = "icon-toast-shibai_huaban";
          break;
        case "loading":
          state.toast.icon = "icon-loading";
          break;
        default:
          state.toast.icon = "icon-toast-jinggao";
          break;
      }
    },
    // 关闭提示组件
    closeToast(state) {
      state.toast.show = false
    },

    // 修改用户xx
    chUresInfo(state, payload) {
      state.UresInfo = payload
    },
    // 修改购物车数量
    chcartTotal(store, payload) {
      store.cartTotal = payload
    }
  },
  actions: {
    AsyncToast({
      commit
    }, payload) {
      commit('openToast', payload);
      setTimeout(() => {
        commit('closeToast')
      }, 2000)
    }
  },
  modules: {
    goods
  }
})
